package com.projecthost.boots.model;

import java.io.Serializable;
import java.util.List;

public class Category implements Serializable {

    private static final long serialVersionUID = -4262649037081383169L;

    private final String name;
    private final String url;
    private final List<Category> subcategories;

    public Category(String name, String url, List<Category> subcategories) {
        this.name = name;
        this.url = url;
        this.subcategories = subcategories;
    }

    public String getName() {
        return name;
    }

    public String getUrl() {
        return url;
    }

    public List<Category> getSubcategories() {
        return subcategories;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((url == null) ? 0 : url.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Category other = (Category) obj;
        if (name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!name.equals(other.name)) {
            return false;
        }
        if (url == null) {
            if (other.url != null) {
                return false;
            }
        } else if (!url.equals(other.url)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Category [name=");
        builder.append(name);
        builder.append(", url=");
        builder.append(url);
        builder.append(", subcategories=");
        builder.append(subcategories);
        builder.append("]");
        return builder.toString();
    }
}
